﻿@using AC.Service.DTO.LiCai
@using AC.Util
@model wychuan2.com.Models.LiCaiAccount
@{
    ViewBag.Title = "理财-设置";
    Layout = "../Shared/_Layout.cshtml";
}

@{
    IList<KeyValuePair<string, string>> lstCategoryType = EnumUtils.GetEnumDescriptions(typeof(CategoryType));
    IList<KeyValuePair<string, string>> lstItemTypes = EnumUtils.GetEnumDescriptions(typeof(ItemType));
    IList<ItemDTO> lstItems = (List<ItemDTO>)ViewBag.Items;
    var lstCategories = (List<CategoryDTO>)ViewBag.Categories;
}

@section styles{
    <link href="~/Content/plugins/jsTree/default/style.css" rel="stylesheet" />
}
<div class="row">
    <div class="col-lg-6">
        <div class="ibox">
            <div class="ibox-title">
                <h4>收支类别</h4>
            </div>
            <div class="ibox-content">
                <div id="treeCategories">
                    <ul>
                        @foreach (var type in lstCategoryType)
                        {
                            <li type="@type.Key" cid="0" parentid="0" class="jstree-open">
                                @type.Value
                                @{
                                    IEnumerable<CategoryDTO> lstCategorys = lstCategories.Where(c => c.InOutType.GetHashCode().ToString().Equals(type.Key) && c.ParentId == 0);
                                    foreach (var category in lstCategorys)
                                    {
                                        <ul>
                                            <li type="@type.Key" cid="@category.Id" parentid="@category.ParentId">
                                                @category.Name
                                                @{
                                                    IEnumerable<CategoryDTO> lstChilds = lstCategories.Where(c => c.ParentId == category.Id);
                                                    foreach (var child in lstChilds)
                                                    {
                                                        <ul>
                                                            <li type="@type.Key" cid="@child.Id" parentid="@child.ParentId">@child.Name</li>
                                                        </ul>
                                                    }
                                                }
                                            </li>
                                        </ul>
                                    }
                                }
                            </li>
                        }
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <div class="col-lg-6">
        <div class="ibox">
            <div class="ibox-title">
                <h4>基础信息</h4>
            </div>
            <div class="ibox-content">
                <div id="treeItems">
                    <ul>
                        @foreach (var itemtype in lstItemTypes)
                        {
                            if (itemtype.Key != ItemType.Category.GetHashCode().ToString())
                            {
                                <li type="@itemtype.Key" cid="0" class="jstree-open">
                                    @itemtype.Value
                                    @{
                                        IEnumerable<ItemDTO> items = lstItems.Where(i => i.Type.GetHashCode().ToString().Equals(itemtype.Key));
                                        if (items.Any())
                                        {
                                            <ul>
                                                @foreach (var item in items)
                                                {
                                                    <li type="@itemtype.Key" cid="@item.Id">@item.Name</li>
                                                }
                                            </ul>
                                        }
                                    }
                                </li>
                            }
                        }
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="modalCategory" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="lblCategory">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="lblCategory">类别信息</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal">
                    <div class="form-group">
                        <label class="control-label col-sm-2">父类别</label>
                        <div class="col-sm-10">
                            <p class="form-control-static" id="lblParentCategory"></p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-2">类别名称</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="txtCategoryName" placeholder="类别名称" />
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" id="btnSaveDesc" class="btn btn-primary">保存</button>
            </div>
        </div>
    </div>
</div>

@section scripts{
    <script src="~/Scripts/plugins/jsTree/jstree.js"></script>
    <script src="~/Scripts/licai/settings.js"></script>
}
